﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<WebSite.Models.ExpenseCategoryModel>" %>
<%@ Import Namespace="WebSite.Models" %>
<%@ Import Namespace="WebSite.App_Code" %>
<%@ Import Namespace="WebSite.App_Data" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Department
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    
    <style type="text/css">
    
    .EC_One { cursor:pointer;}
    .EC_One:hover { color:Red; }
    
    .Active { font-weight:bold; }
    
    </style>

    <script type="text/javascript">

        $(document).ready(function () {

            if ('<%=ViewData.ContainsKey("DB.Operation.Result") %>' == "True")
                alert('<%=ViewData["DB.Operation.Result"] %>');

        });

        function GetParent(sender, pid) {

            var parent_sel = $("select", $(sender).parents("td:eq(0)").next());

            $("option", parent_sel).remove();

            $.getJSON("/MasterData/ExpenseCategory_GetParent", { Group: $(sender).val() }, function (json) {

                if (json.length == 0) { parent_sel.hide(); }
                else { parent_sel.show(); }
                $.each(json, function (i, item) {

                    if (pid == item.Value)
                        parent_sel.append("<option value='" + item.Value + "' selected=selected>" + item.Text + "</option>");
                    else
                        parent_sel.append("<option value='" + item.Value + "'>" + item.Text + "</option>");
                });
            });

        }

        function SelectEC(sender) {

            var selected = $("tr[selected=selected]");

            if (selected.length > 0) { selected.attr("class", selected.attr("class").replace(" Active", "")); }

            $(sender).attr("class", $(sender).attr("class") + " Active");
            $(sender).attr("selected", "selected");

            var ID = $("input[name=ID]", $(sender)).val();
            var Name = $("input[name=Name]", $(sender)).val();
            var Group = $("input[name=Group]", $(sender)).val();
            var GroupName = $("input[name=GroupName]", $(sender)).val();
            var PID = $("input[name=PID]", $(sender)).val();
            var PName = $("input[name=PName]", $(sender)).val();
            var HasC = $("input[name=HasC]", $(sender)).val();

            $("input[name=D_ID]").val(ID);
            $("input[name=D_Name]").val(Name);
            $("select[name=D_Group]").html("<option>" + GroupName + "</option>")
            $("select[name=D_PID]").html("<option>" + PName + "</option>")
            if (HasC) { $("input[name=D_HasC]").attr("checked", "checked"); }

            $("input[name=U_ID]").val(ID);
            $("input[name=U_Name]").val(Name);
            $("select[name=U_Group]").val(Group);
            $("select[name=U_Group]").bind("change", function () { GetParent(this, PID); });
            $("select[name=U_Group]").change();
            if (HasC) { $("input[name=U_HasC]").val("on"); }

            $("input[name=ID]").val(ID);

            $("#dvDetail").show();
            $("#dvUpdate").hide();
            $("#dvInsert").hide();

            location.hash = ""; 
            location.hash = "#dvDetail";
        }

        function OpenInset() {
            $("#dvDetail").hide();
            $("#dvUpdate").hide();
            $("#dvInsert").show();
        }

        function OpenEdit() {
            if ($("input[name=U_ID]").val() == "") { alert("请选择科目"); return; }

            $("#dvDetail").hide();
            $("#dvUpdate").show();
            $("#dvInsert").hide();
        }

        function DoDisable() { if (confirm("是否删除该费用科目?")) { $("#btnDisable").click(); } }

        function DoEnable() { $("#btnEnable").click(); }

        function DoQuery(sender) {

            if (sender.checked) { $("[name=IsAll]").val("True") }
            $("#btnQuery").click();
        }

    </script>

    显示无效科目<input type="checkbox" onclick="DoQuery(this)" <%if(Model.IsAll){%> checked="checked" <%} %> />

    <table border="0" cellpadding="0" cellspacing="1" class="masterdatatable">
        <tr class="masterdatatable_header">
            <td>费用科目</td>
            <td>层级</td>
            <td>父科目</td>
            <td>允许三级科目</td>
        </tr>            
    <% for (int i = 0; i < Model.ECList.Count; i++)
       { %>
        <% if (Model.ECList[i].Category.Status)
           { %> 
            <tr class="masterdatatable_enable EC_One" onclick="SelectEC(this)"> 
        <% }
           else
           { %> 
            <tr class="masterdatatable_disable EC_One" onclick="SelectEC(this)">  
        <% } %>
            <td>
                <%=Html.Hidden("ID", Model.ECList[i].Category.Guid) %>
                <%=Html.Hidden("Name", Model.ECList[i].Category.CategoryName) %>
                <%=Html.Hidden("Group", Model.ECList[i].Category.CategoryGroup) %>
                <%=Html.Hidden("GroupName", Model.ECList[i].Group.CategoryGroupName) %>
                <%=Html.Hidden("PID", Model.ECList[i].Category.ParentGuid) %>
                <%=Html.Hidden("PName", Model.ECList[i].Parent.CategoryName) %>
                <%=Html.Hidden("HasC", Model.ECList[i].Category.HasChid) %>
                <%=Model.ECList[i].Category.CategoryGroup%>
                <%=Model.ECList[i].Category.CategoryName%>
            </td>
            <td><%=Model.ECList[i].Group.CategoryGroupName%></td>
            <td><%=Model.ECList[i].Parent.CategoryName%></td>
            <td><%=Model.ECList[i].Category.HasChid ? "是" : "否"%></td>
        </tr>
    <%} %>
    </table>
    <br/><br/>
    <input type="button" class="budget-button-no-01" value="添加" style=" width:80px;" onclick="OpenInset()" />
    <input type="button" class="budget-button-no-01" value="修改" style=" width:80px;" onclick="OpenEdit()" />
    <input type="button" class="budget-button-no-01" value="删除" style=" width:80px;" onclick="DoDisable()" />
    <input type="button" class="budget-button-no-01" value="启动" style=" width:80px;" onclick="DoEnable()" />
    <div id="dvInsert" style="display:none">
    <%using (Html.BeginForm("ExpenseCategory_Insert", "MasterData", new { ShowAll = Model.IsAll }, FormMethod.Post)) { %>
        <table>
            <tr><td>费用科目</td><td>层级</td><td>父科目</td><td>允许三级科目</td></tr>
            <tr>
                <td><input name="I_Name" class="budget-txt-no-01" /><input name="I_ID" type="hidden" /></td>
                <td><%=Html.DropDownList("I_Group", Model.EC.GroupSource, new { @onchange = "GetParent(this)" })%></td>
                <td><select name="I_PID" style="display:none"></select></td>
                <td><input name="I_HasC" type="checkbox" /></td>
                <td><input type="submit" class="budget-button-no-01" value="确定" style=" width:80px;" /></td>
            </tr>
        </table>
    <%} %>
    </div>
    <div id="dvUpdate" style="display:none">
    <%using (Html.BeginForm("ExpenseCategory_Upadte", "MasterData", new { ShowAll = Model.IsAll }, FormMethod.Post))
      { %>
        <table>
            <tr><td>费用科目</td><td>层级</td><td>父科目</td><td>允许三级科目</td></tr>
            <tr>
                <td><input name="U_Name" class="budget-txt-no-01" /><input name="U_ID" type="hidden" /></td>
                <td><%=Html.DropDownList("U_Group", Model.EC.GroupSource)%></td>
                <td><select name="U_PID"></select></td>
                <td><input name="U_HasC" type="checkbox" /></td>
                <td><input type="submit" class="budget-button-no-01" value="确定" style=" width:80px;" /></td>
            </tr>
        </table>
    <%} %>
    </div>
    <div id="dvDetail" style="display:none">
        <table>
            <tr><td>费用科目</td><td>层级</td><td>父科目</td><td>允许三级科目</td></tr>
            <tr>
                <td><input name="D_Name" class="budget-txt-no-01" disabled="disabled" /><input name="D_ID" type="hidden" /></td>
                <td><select name="D_Group" disabled="disabled"></select></td>
                <td><select name="D_PID" disabled="disabled"></select></td>
                <td><%=Html.CheckBox("D_HasChild", new { @disabled = "disabled" })%></td>
            </tr>
        </table>
    </div>
    <div id="dvDelete" style="display:none">
    <%using (Html.BeginForm("ExpenseCategory_Disable", "MasterData", new { ShowAll = Model.IsAll }, FormMethod.Post))
      { %>
        <input id="btnDisable" type="submit" class="budget-button-no-01" value="确定" style=" width:80px;" />
        <input name="ID" type="hidden" />
    <%} %>
    </div>
    <div id="dvEnable" style="display:none">
    <%using (Html.BeginForm("ExpenseCategory_Enable", "MasterData", new { ShowAll = Model.IsAll }, FormMethod.Post))
      { %>
        <input id="btnEnable" type="submit" class="budget-button-no-01" value="确定" style=" width:80px;" />
        <input name="ID" type="hidden" />
    <%} %>
    </div>
    <div style="display:none">
    <%using (Html.BeginForm("ExpenseCategory_Query", "MasterData", FormMethod.Post))
      { %>
        <input id="btnQuery" type="submit" class="budget-button-no-01" value="确定" style=" width:80px;" />
        <input name="IsAll" type="hidden" />
    <%} %>
    </div>
    <br /><br /><br /><br /><br />
</asp:Content>
